package com.example.comzg24_2

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.runBlocking

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

fun main()= runBlocking(){
    val flow = flow<Int>{
        for (i in 1..5){
            emit(i)
            delay(500)
        }
    }

    flow.collect{value ->
        println("接收数据：$value")
    }



    val list = mutableListOf<Int>()
    var list2 = mutableListOf<Int>()
    for (i in 1..10){
        list.add(i)
    }
    list.forEach {
        if(it%2==0){
            list2.add(it)
        }
    }
    println(list2)
}